package com.bcx.service.impl;

import com.bcx.mapper.EntryMapper;
import com.bcx.pojo.Entry;
import com.bcx.pojo.EntryExample;
import com.bcx.service.EntryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class EntryServiceImpl implements EntryService {
    @Resource
    EntryMapper entryMapper;
    @Override
    public PageInfo<Entry> selectAll(Integer categoryid, Integer pageNum) {
        EntryExample entryExample=new EntryExample();
        EntryExample.Criteria criteria=entryExample.createCriteria();
        criteria.andCategoryidEqualTo(categoryid);
        PageHelper.startPage(pageNum,2);
        List<Entry>entries= entryMapper.selectByExample(entryExample);
        PageInfo<Entry> pageInfo=new PageInfo<>(entries);
        return pageInfo;
    }

    @Override
    public void insert(Entry entry) {
    entryMapper.insert(entry);
    }

    @Override
    public void delete(Integer id) {
    entryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Entry getById(Integer id) {
        return entryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Entry entry) {
    entryMapper.updateByPrimaryKeySelective(entry);
    }
}
